package de.lazy.gui.components;

import javax.swing.JPanel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JSeparator;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

public class TitleLabel extends JPanel {
	
	private JLabel textLabel;
	private JLabel titleLabel;
	
	public TitleLabel(String title, String text){
		textLabel = new JLabel(text);
		titleLabel = new JLabel(title);
		
		setLayout(new BorderLayout(0, 0));
		
		add(textLabel, BorderLayout.CENTER);
				
		titleLabel.setBorder(new EmptyBorder(0, 0, 0, 5));
		add(titleLabel, BorderLayout.WEST);
	}
	
	public TitleLabel() {
		this("title","text");
	}

	public void setText(String text){
		textLabel.setText(text);
	}
	
	public void setTitle(String title){
		titleLabel.setText(title);
	}
	
	public JLabel getTextLabel() {
		return textLabel;
	}

	public void setTextLabel(JLabel textLabel) {
		this.textLabel = textLabel;
	}

	public JLabel getTitleLabel() {
		return titleLabel;
	}

	public void setTitleLabel(JLabel titleLabel) {
		this.titleLabel = titleLabel;
	}

	@Override
	public void setPreferredSize(Dimension preferredSize) {
		super.setPreferredSize(preferredSize);
		
		Dimension teSize = textLabel.getPreferredSize();
		teSize.height = preferredSize.height;
		textLabel.setPreferredSize(teSize);
		
		Dimension tlSize = titleLabel.getPreferredSize();
		tlSize.height = preferredSize.height;
		titleLabel.setPreferredSize(tlSize);
	}

	@Override
	public void setForeground(Color fg) {
		if(titleLabel == null || textLabel == null){
			super.setForeground(fg);
			return;
		}
		titleLabel.setForeground(fg);
		textLabel.setForeground(fg);
	}
	
	public void setForeground(Color title,Color text) {
		if(titleLabel == null || textLabel == null){
			return;
		}
		titleLabel.setForeground(title);
		textLabel.setForeground(text);
	}
	
	
}
